﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DeployGames.TweenEngine.equations
{
    public abstract class Back : TweenEquation
    {
        public static BackIN IN = new BackIN();
        public static BackOUT OUT = new BackOUT();
        public static BackINOUT INOUT = new BackINOUT();

        #region BackIN
        public class BackIN : Back
        {
            public override float compute(float t)
            {
                float s = param_s;
                return t * t * ((s + 1) * t - s);
            }
            public override string ToString()
            {
                return "Back.IN";
            }
        }
        #endregion

        #region BackOUT
        public class BackOUT : Back
        {
            public override float compute(float t)
            {
                float s = param_s;
                return (t -= 1) * t * ((s + 1) * t + s) + 1;
            }

            public override string ToString()
            {
                return "Back.OUT";
            }
        }
        #endregion

        #region BackINOUT
        public class BackINOUT : Back
        {
            public override float compute(float t)
            {
                float s = param_s;
                if ((t *= 2) < 1) return 0.5f * (t * t * (((s *= (1.525f)) + 1) * t - s));
                return 0.5f * ((t -= 2) * t * (((s *= (1.525f)) + 1) * t + s) + 2);
            }
            public override string ToString()
            {
                return "Back.INOUT";
            }
        }
        #endregion
        
        protected float param_s = 1.70158f;

        public Back s(float s)
        {
            param_s = s;
            return this;
        }
    }
}
